#pragma once


#ifdef _UNICODE
	#define XML_UNICODE_WCHAR_T
#endif
#include "TextReader.h"
#include "expatpp.h"
#include "Skeleton.h"
#include "Bone.h"
#include <stack>
/**
* Reads the bones as exported from 3D Studio Max
* @author Koen Samyn
*/
class BoneReader: public TextReader, expatpp
{
public:
	/**
	* Creates a new bonereader with the provided filename.
	* @param filename the filename to read.
	*/
	BoneReader(tstring filename);
	/**
	* Destroys the BoneReader object.
	*/
	virtual ~BoneReader(void);
	/**
	* Reads the file, returns true if the read operation was succesful.
	* @return true if reading the file was succesful , false otherwise.
	*/
	bool Read();
	/**
	* Returns the result of this file,namely a skeleton.
	*/
	Skeleton* GetSkeleton(){
		return m_pSkeleton;
	}
	/**
	* This method is called when a new xml element is encountered.
	* @param name the name of the element.
	* @param atts the attributes for the element.
	*/
	void startElement(const XML_Char *name, const XML_Char **atts);
	/**
	* This method is called when an xml element ends.
	* @param name the name of the element.
	*/
	void endElement(const XML_Char* name);
	/**
	* This method is called for the contents of the element.
	* @param s the contents of an element.
	* @param len the length of this element.
	*/
	void charData(const XML_Char *s, int len);

	void startNamespace(const XML_Char* /* prefix */, const XML_Char* /* uri */){}

	void endNamespace(const XML_Char*){}

	void processingInstruction(const XML_Char*, const XML_Char*){}
	
	void defaultHandler(const XML_Char*, int){}

	void unparsedEntityDecl(const XML_Char*, const XML_Char*, const XML_Char*, const XML_Char*, const XML_Char*){}

	void notationDecl(const XML_Char*, const XML_Char*, const XML_Char*, const XML_Char*){}

private:
	/**
	* Pointer to the created skeleton.
	*/
	Skeleton* m_pSkeleton;
	/**
	* Pointer to the current node.
	*/
	SkeletonNode* m_pCurrentNode;
	/**
	* Pointer to the current bone
	*/
	SkeletonNode* m_pCurrentBone;
	/**
	* The stack with the nodes
	*/
	stack<SkeletonNode*> m_NodeStack;
	// -------------------------
	// Disabling default copy constructor and default assignment operator.
	// If you get a linker error from one of these functions, your class is internally trying to use them. This is
	// an error in your class, these declarations are deliberately made without implementation because they should never be used.
	// -------------------------

	BoneReader(const BoneReader& t);
	BoneReader& operator=(const BoneReader& t);
};
